#!/bin/sh
#
# MySQL server maintenance with mysqlbackup(1) tool.
#
# Configurable tunes:
# 
# mysqlbackup_enable (bool): 	enables or disables mysqlbackup(1) tool. The
# 				default is "no".
#
# mysqlbackup_schedule (str):	run mysqlbackup(1) either `daily' or `weekly'
# 				or `monthly'.  By default mysqlbackup(1) runs
# 				by a daily schedule.
#
# mysqlbackup_args (str):	pass to mysqlbackup(1) program additional
# 				arguments. By default they are set to "-av",
# 				which means to backup all the available
# 				databases.  For any other arguments please
# 				check the manual page for mysqlbackup.
#
# $Id$

# If there is a global system configuration file, suck it in.
#
if [ -r /etc/defaults/periodic.conf ]
then
    . /etc/defaults/periodic.conf
    source_periodic_confs
fi

: ${mysqlbackup_enable="no"}
: ${mysqlbackup_schedule="daily"}
: ${mysqlbackup_args="-av"}

mysqlbackup=%%PREFIX%%/bin/mysqlbackup

do_backup() 
{
	echo; echo "Creating MySQL server backups"

	rc=1
	${mysqlbackup} ${mysqlbackup_args} || rc=2
	
	echo "MySQL server backup done";

	return 0
}

rc=0
case "${mysqlbackup_enable}" in
	[Yy][Ee][Ss])
	case "${mysqlbackup_schedule}" in
		[dD][aA][iI][lL][yY]) do_backup ;;
		[wW][eE][eE][kK][lL][yY]);;
		[mM][oO][nN][tT][hH][lL][yY]);;
	esac;;
esac

exit ${rc}
